package 长度为K的子数组的能量值I3254;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Deque;
import java.util.LinkedList;

public class Solution {
    public int[] resultsArray(int[] nums, int k) {
        if(nums.length == 1 || k == 1) {
            return nums;
        }
        int[] res = new int[nums.length - k + 1];
        Arrays.fill(res, -1);
        int left = 0;
        int right = 0;
        int count = 0;
        for(int i = 1; i < k; ++i) {
            if(nums[i - 1] == nums[i] - 1) {
                count++;
            }else {
                count = 0;
            }
            right++;
        }
        if(count >= k) {
            res[0] = nums[right];
        }
        while(right < nums.length || left < res.length) {
            if(nums[right] == nums[right - 1] + 1) {
                count++;
            }else {
                count = 1;
            }
            if(count >= k) {
                res[left] = nums[right];
            }
            left++;
            right++;
        }
        return res;
    }
}
